package com.bwie.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bwie.pojo.TbItem;
import com.bwie.service.TbItemService;
import com.bwie.mapper.TbItemMapper;
import com.bwie.utils.R;
import com.bwie.vo.ReviewDTO;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
* @author wx200
* @description 针对表【tb_item】的数据库操作Service实现
* @createDate 2025-07-03 20:34:44
*/
@Service
public class TbItemServiceImpl extends ServiceImpl<TbItemMapper, TbItem>
    implements TbItemService{

    /**
     * 提交初审结果
     * @param dto 包含项目ID和初审状态
//     * @throws BusinessException 业务异常
     */
    @Transactional
    public R submitReview(ReviewDTO dto) {
        // 1. 查询项目是否存在
        TbItem tbItem = this.getById(dto.getId());
        if (tbItem == null) {
          return R.ERROR(500,"项目不存在");
        }

        // 2. 校验状态（仅未初审或初审不通过的项目可修改）
        if (tbItem.getReviewStatus() == 1) {
          return R.ERROR(500,"项目已初审通过，不可重复提交");
        }

        // 3. 更新初审状态
        tbItem.setReviewStatus(dto.getReviewStatus());
        boolean success = this.updateById(tbItem);
        if (!success) {
            return R.ERROR(500,"初审提交失败");
        }
        return R.OK();
    }


}




